package com.kili.file.controller.vo;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.kili.file.enums.ResponseCode;
import lombok.AllArgsConstructor;
import lombok.Data;

import java.io.Serializable;

/**
 * BaseResponse
 *
 * @author Gordon
 * @version 2019/4/15
 */
@Data
@AllArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
public class BaseResponse<T> implements Serializable {
    /**
     * status
     */
    private int    status;
    /**
     * response msg
     */
    private String msg;
    /**
     * data
     */
    private T      data;


    public BaseResponse(int status) {
        this.status = status;
    }

    public BaseResponse(int status, String msg) {
        this.status = status;
        this.msg = msg;
    }

    public BaseResponse(int status, T date) {
        this.status = status;
        this.data = date;
    }

    public static <T> BaseResponse<T> of() {
        return new BaseResponse<>(ResponseCode.SUCCESS.getCode(), ResponseCode.SUCCESS.getMsg());
    }

    public static <T> BaseResponse<T> of(T data) {
        return new BaseResponse<>(ResponseCode.SUCCESS.getCode(), ResponseCode.SUCCESS.getMsg(), data);
    }

    public static <T> BaseResponse<T> of(ResponseCode code) {
        return new BaseResponse<>(code.getCode(), code.getMsg());
    }

    public static <T> BaseResponse<T> of(int code, String msg, T data) {
        return new BaseResponse<>(code, msg, data);
    }

}
